package com.example.javamaday.leetcode;

import java.util.Arrays;

public class LeetCodeTest0088 {

    public static void main(String[] args) {
        new LeetCodeTest0088().merge(new int[]{1, 2, 3, 0, 0, 0}, 3, new int[]{2, 5, 6}, 3);
    }

    public void merge(int[] nums1, int m, int[] nums2, int n) {
        int mIndex = m - 1;
        int nIndex = n - 1;
        for (int i = m + n - 1; i >= 0; i--) {
            if (mIndex == -1 && nIndex >= 0) {
                nums1[i] = nums2[nIndex];
                nIndex--;
                continue;
            }
            if (nIndex == -1) {
                break;
            }
            if (mIndex >= 0 && nIndex >= 0) {
                if (nums1[mIndex] >= nums2[nIndex]) {
                    nums1[i] = nums1[mIndex];
                    mIndex--;
                } else {
                    nums1[i] = nums2[nIndex];
                    nIndex--;
                }
            }
        }
        System.out.println(Arrays.deepToString(new int[][]{nums1}));
    }
}
